package com.rjwh.dingdong.client.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.aishua.lib.utils.AsStrUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.rjwh.dingdong.client.R;
import com.rjwh.dingdong.client.bean.localbean.PersonalCenterMenuData;
import com.rjwh.dingdong.client.util.ViewHolder;

/**
 * @author Kay
 * @ClassName MoreMenuListAdapter
 * @Description 个人中心菜单列表
 * @date 2016-11-30
 * @history 2016-11-30 author: description:
 */
public class MoreMenuListAdapter extends AdapterBase<PersonalCenterMenuData> {

    private Context context;

    public MoreMenuListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected View getExView(int position, View convertView, ViewGroup parent) throws Exception {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.more_menu_item_layout, null);
        }
        ImageView moreMenuImage = ViewHolder.get(convertView, R.id.more_menu_image);
        TextView moreMenuTitle = ViewHolder.get(convertView, R.id.more_menu_title);
        TextView moreMenuAccessory = ViewHolder.get(convertView, R.id.more_menu_accessory);

        PersonalCenterMenuData personalCenterMenuData = getList().get(position);
        if (personalCenterMenuData == null) {
            return convertView;
        }
        String icon = personalCenterMenuData.getIcon();
        String title = personalCenterMenuData.getTitle();
        String accessory = personalCenterMenuData.getAccessory();

        if (!AsStrUtils.isEmpty(title)) {
            moreMenuTitle.setText(title);
        }
        if (!AsStrUtils.isEmpty(accessory)) {
            moreMenuAccessory.setText(accessory);
        }

        Glide.with(context).load(icon).dontAnimate()
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(moreMenuImage);

        return convertView;
    }
}
